package cn.yll.api.user.service;

import cn.yll.api.user.request.UserCashRequest;
import cn.yll.api.user.request.UserPwdLoginRequest;
import cn.yll.api.user.request.UserRegisterRequest;
import cn.yll.api.user.response.UserBaseResponse;
import cn.yll.common.exception.BsErrEnum;
import cn.yll.common.exception.BsException;
import cn.yll.common.module.RestModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
/**
 * 用户服务熔断降级回退接口
 * @author yangll
 */
@Slf4j
@Component
public class RemoteUserFeignFallbackFactory implements FallbackFactory<RemoteUserFeignService> {
    @Override
    public RemoteUserFeignService create(Throwable cause) {
        return new RemoteUserFeignService() {
            @Override
            public RestModel<UserBaseResponse> register(UserRegisterRequest user) {
                log.info("注册用户失败--fall-back--", cause.getCause());
                throw new BsException(BsErrEnum.RPC_ERROR);
            }

            @Override
            public RestModel<UserBaseResponse> validUserPwd(UserPwdLoginRequest request) {
                log.info("~~~~~~~~~openfeign fallback~~~~~~~~", cause.getCause());
                throw new BsException(BsErrEnum.RPC_ERROR);
            }

            @Override
            public RestModel<Boolean> addCash(UserCashRequest request) {
                log.info("用户充值或消费失败--fall-back--", cause.getCause());
                throw new BsException(BsErrEnum.RPC_ERROR);
            }

            @Override
            public RestModel<UserBaseResponse> getUserById(Long userId) {
                log.info("根据用户ID查询用户失败--fall-back--", cause.getCause());
                throw new BsException(BsErrEnum.RPC_ERROR);
            }

            @Override
            public RestModel<UserBaseResponse> getByUserName(String userName) {
                log.info("根据用户名查询用户失败--fall-back--", cause.getCause());
                throw new BsException(BsErrEnum.RPC_ERROR);
            }

            @Override
            public RestModel<UserBaseResponse> getByPhone(String phone) {
                log.info("根据手机号查询用户失败--fall-back--", cause.getCause());
                throw new BsException(BsErrEnum.RPC_ERROR);
            }
        };
    }
}
